<script setup lang="ts">
import { useCategoryStore } from '@/store/modules/category'
import { onMounted } from 'vue'

// 引入相关仓库
const categoryStore = useCategoryStore()

//初始化调用
onMounted(() => {
  categoryStore.getC1()
})

//一级分类下拉菜单选中值发生变化触发
const handlerc1Change = () => {
  categoryStore.c2Id = ''
  categoryStore.c3Id = ''
  categoryStore.c3Arr = []
  categoryStore.getC2()
}
//二级分类下拉菜单选中值发生变化触发
const handlerc2Change = () => {
  categoryStore.c3Id = ''
  categoryStore.getC3()
}
//获取父组件的prop
const props = defineProps<{ scene: number }>()
</script>

<template>
  <el-card>
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <el-select
          placeholder="请选择"
          filterable
          clearable
          v-model="categoryStore.c1Id"
          @change="handlerc1Change"
          :disabled="props.scene == 1 ? true : false"
        >
          <el-option
            :label="c1.name"
            :value="c1.id"
            v-for="c1 in categoryStore.c1Arr"
            :key="c1.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          placeholder="请选择"
          filterable
          clearable
          v-model="categoryStore.c2Id"
          @change="handlerc2Change"
          :disabled="props.scene == 1 ? true : false"
        >
          <el-option
            :label="c2.name"
            :value="c2.id"
            v-for="c2 in categoryStore.c2Arr"
            :key="c2.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          placeholder="请选择"
          filterable
          clearable
          v-model="categoryStore.c3Id"
          :disabled="props.scene == 1 ? true : false"
        >
          <el-option
            :label="c3.name"
            :value="c3.id"
            v-for="c3 in categoryStore.c3Arr"
            :key="c3.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<style lang="scss" scoped></style>
